package haierhome.krund.cn.daggertworetrofitrxjavamvp.rxjava.retrofiteasefram;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import java.util.HashMap;
import haierhome.krund.cn.daggertworetrofitrxjavamvp.R;
import haierhome.krund.cn.daggertworetrofitrxjavamvp.retrofit.bean.UserLogin;
import haierhome.krund.cn.daggertworetrofitrxjavamvp.rxjava.retrofiteasefram.retrofit.RetrofitApi;
import haierhome.krund.cn.daggertworetrofitrxjavamvp.rxjava.retrofiteasefram.retrofit.RxJavaRetorfitUtils;
import rx.Observable;

public class RetrofitEasyFramActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_retrofit_easy_fram);

        findViewById(R.id.bt_http).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initPostUrl();
            }
        });
    }

    /**
     * Retrofit再次封装
     */
    private void initPostUrl() {

        HashMap<String, String> map = new HashMap<>();
        map.put("username", "545056@qq.com");
        map.put("password", "Spl901006ms");

        RetrofitApi retrofitApi = RxJavaRetorfitUtils.getInstance().initRxJavaRetorfitUtils();

        Observable<UserLogin> observable = retrofitApi.postLoginRequest(map);

        RxJavaRetorfitUtils.getInstance().httpRequest(this, observable,

                new RxJavaRetorfitUtils.RetrofitCallBack<UserLogin>() {

                    @Override
                    public void onSuccess(UserLogin userLogin) {
                        Log.i("1111", "1111");
                    }

                    @Override
                    public void onError(int code, String msg) {
                        Log.i("1111", "1111");
                    }
                });
    }
}
